class Solution {
public:
    int maxConsecutiveAnswers(string answerKey, int k)
    {
        int n = answerKey.size();
        function<int(char)> maxhard = [&](char ch)->int {
            int ans = 0;
            for (int left = 0, right = 0, sum = 0; right < n; right++)
            {
                sum += answerKey[right] != ch;
                while (sum > k)
                    sum -= answerKey[left++] != ch;
                ans = max(ans, right - left + 1);
            }
            return ans;
            };
        return max(maxhard('T'), maxhard('F'));
    }
};